<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
<script src="layui/layui.js" type="text/javascript" charset="UTF-8"></script>
<script src="js/jquery-1.8.2.js"></script>
</head>
<body>
<form class="layui-form" action="Tianjiachanpinxinxi" method="get">
 <label class="layui-form-label">车型</label>
    <div class="layui-input-block">
      <select name="chexing" lay-filter="aihao">
        <option value="1">公交客车</option>
        <option value="2">客运客车</option>
        <option value="3">旅游客车</option>
        <option value="4">专用车</option>
        <option value="5">企事业通勤客车</option>
        <option value="6">公商务车</option>
        <option value="7">房车</option>
        <option value="8">景区车</option>
        <option value="9">机场摆渡车</option>
        <option value="10">校车</option>
      </select>
    </div>
  

 
  <div class="layui-form-item">
    <label class="layui-form-label" >动力：</label>
    <div class="layui-input-block">
      <input type="text" name="dongli" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label" >座位：</label>
    <div class="layui-input-block">
      <input type="text" name="zuowei" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  
   <div class="layui-form-item">
    <label class="layui-form-label" >车长：</label>
    <div class="layui-input-block">
      <input type="text" name="chechang" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label" >要求：</label>

    <div class="layui-input-block">
      <input type="text" name="yaoqiu" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>


  <label class="layui-form-label">排放:</label>
    <div class="layui-input-block">
      <input type="text" name="paifang" required  lay-verify="required" placeholder="请输入排放" autocomplete="off" class="layui-input">
    </div>
    

  <label class="layui-form-label">发动机:</label>
    <div class="layui-input-block">
      <input type="text" name="fadongji" required  lay-verify="required" placeholder="请输入发动机" autocomplete="off" class="layui-input">

  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label" >排放：</label>
    <div class="layui-input-block">
      <input type="text" name="paifang" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label" >发动机：</label>
    <div class="layui-input-block">
      <input type="text" name="fadongji" placeholder="请输入" autocomplete="off" class="layui-input">

    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label" >名字：</label>
    <div class="layui-input-block">
      <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
   <label class="layui-form-label">商品封面</label>
  <button type="button" class="layui-btn" id="test">
<i class="layui-icon">&#xe67c;</i>上传图片
</button>
<img id="tupian"/>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
     <button lay-submit lay-filter="*" class="layui-btn">提交</button>     
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script>
layui.use('upload', function(){
	  var upload = layui.upload;
	   
	  //执行实例
	  var uploadInst = upload.render({
	    elem: '#test' //绑定元素
	    ,url: 'upload' //上传接口
	    ,done: function(res){
	      //上传完毕回调
	      
	    $("#tupian").attr("src",res.data).css("width", "200px")
		.css("hight", "150px");;
	    
	    }
	    ,error: function(){
	      //请求异常回调
	    }
	  });
	});
//==================================================
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //执行一个laydate实例
  laydate.render({
    elem: '#test1' //指定元素
  });
});
//==================================================
layui.use('form', function(){
	  var form = layui.form;
form.on('submit(*)', function(data){
	  console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
	  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
	  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
	  
	  data.field.img =  $("#tupian").attr("src");
	  
	  $.ajax({
		  url:"Tianjiachanpinxinxi",//地址
		  type:"get",//请求方式
		  data:data.field,//参数
		  success : function(res) {
				if (res == 1) {
					layer.confirm('添加成功！');
					window.location.reload();
				} else {
					layer.confirm('添加失败！');
				}
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index); 
				 window.parent.location.reload();
			}


	  });
	  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	});
});
</script>
</body>
</html>